<template>
  <div>
    <!-- <el-button class="fr mb20" type="primary" @click="handleEdit('add', {})">新增</el-button> -->
    <e-table
      ref="eTable"
      @getList="handleGetList"
      :tableData="tableData"
      :columns="columns"
      :loading="loading"
      :total="total"
    >
      <el-table-column label="状态" width="80" slot="state" align="center">
        <template slot-scope="scope">
          <el-tag
            :type="scope.row.state === 1 ? 'success' : 'null' "
          >{{ scope.row.selfCommitTime ? ( scope.row.committeeCommitTime ? '已完成' : '审核中' ) : '待考评' }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="流程状态" slot="status" align="center">
        <template slot-scope="scope">{{ computeStatus(scope.row) }}</template>
      </el-table-column>
      <el-table-column slot="action" fixed="right" width="50" align="center">
        <template slot-scope="scope">
          <el-dropdown>
            <a class="el-dropdown-link">
              <i class="el-icon-menu"></i>
            </a>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item
                @click.native="handleEdit('edit', scope.row)"
                v-if="!scope.row.selfCommitTime"
              >
                <a>编辑</a>
              </el-dropdown-item>
              <el-dropdown-item @click.native="handleEdit('view', scope.row)">
                <a>查看</a>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </e-table>
  </div>
</template>

<script>
import { notePage } from '@/api/morality'

export default {
  data() {
    return {
      tableData: [],
      total: 1,
      loading: false,
      columns: [
        {
          label: '科室名称',
          prop: 'deptName'
        },
        {
          label: '姓名',
          prop: 'name'
        },
        {
          label: '考评方案名称',
          prop: 'moralityPlanName'
        },
        { slot: 'state' },
        { slot: 'status' },
        // {
        //   label: '流程状态',
        //   prop: ''
        // },
        { slot: 'action' }
      ],
      queryParam: {
        pageNo: 1,
        pageSize: 10
      }
    }
  },
  mounted() {
    this.handleGetList()
  },
  methods: {
    // 新增，编辑，查看
    handleEdit(type, row, from = 'person') {
      this.$router.push({
        name: 'medicalEthicsCreatePerson',
        params: { type, row, from }
      })
    },
    async handleGetList(param = {}) {
      this.loading = true
      this.queryParam = Object.assign(this.queryParam, param)
      const res = await notePage(this.queryParam)

      if (res && res.data.records.length > 0) {
        const {
          state,
          data: { records, total }
        } = res
        this.tableData = records
        this.total = total
      } else {
        this.tableData = []
        this.total = 1
      }
      this.loading = false
    },
    computeStatus(row) {
      if (row.selfCommitTime) {
        if (row.deptCommitTime) {
          if (row.branchCommitTime) {
            if (row.committeeCommitTime) {
              return '考评完成'
            } else {
              return ''
            }
          } else {
            if (row.branchStep) {
              return '党支部考评'
            } else {
              return '考评委员会考评'
            }
          }
        } else {
          return '科室考评'
        }
      } else {
        return '个人自评'
      }
    }
  }
}
</script>
